<template>
  <p-breadcrumb class="breadcrumb">
      <p-breadcrumb-item v-for="(item, index) in breadList" :key="index">
        <router-link v-if="item.name != name" :to="{ path: item.path }">
          {{ item.meta.title }}
        </router-link>
        <span v-else>{{ item.meta.title }}</span>
      </p-breadcrumb-item>
    </p-breadcrumb>
</template>

<script>
export default {
  data () {
    return {
      name: '',
      path: '',
      breadList: []
    }
  },
  created () {
    console.log(this.$router)
    console.log(this.$route)
    this.getBreadcrumb()

  },
  methods: {
    getBreadcrumb () {
      this.breadList = []
      this.breadList.push({name: 'index', path: '/dashboard/', meta: {title: '首页'}})
      this.name = this.$route.name
      this.path = this.$route.path
      // console.error(this.$route)
      this.$route.matched.forEach((item,index) => {
        // item.name !== 'index' && this.breadList.push(item)
        if(index > 0){
          this.breadList.push(item)
        }
      })
    }
  },
  watch: {
    $route () {
      this.getBreadcrumb()
    }
  }
}
</script>

<style scoped>
</style>
